package com.yunmang;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

import com.yunmang.DaoUtils.DaoManager;
import com.yunmang.entity.CarListBean;
import com.yunmang.entity.ConfigBean;
import com.yunmang.entity.DatabaseEntity.Student;
import com.yunmang.entity.MemberBean;
import com.yunmang.entity.NameBean;
import com.yunmang.entity.PackageBean;
import com.yunmang.http.CommonSubscriber;
import com.yunmang.http.HttpUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import rx.Subscriber;

public class MainActivity extends AppCompatActivity {

    @InjectView(R.id.btn_login)
    Button btnLogin;
    private Subscriber subscriber;
    private CommonSubscriber commonSubscriber;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);
        DaoManager.getInstance().getDaoSession().insert(new Student());
    }


    @OnClick(R.id.btn_login)
    public void onClick() {
//        getAllCar();
    //        login("zhengzhou","12456");
        getAllPackages();
//        getConfigParams();
//        getMemberInfo("200");
//        getShipperName("123");
        print();
    }

    private void print() {
    }

    private void getShipperName(String phone) {
        commonSubscriber=new CommonSubscriber<NameBean>(this) {
            @Override
            public void requestSuccess(NameBean nameBean) {
                Toast.makeText(MainActivity.this,nameBean.getCode()+"", Toast.LENGTH_SHORT).show();
            }
        };
        HttpUtils.getInstance().getshipper(commonSubscriber,phone);
    }

    private void getMemberInfo(String code) {
        subscriber=new Subscriber<MemberBean>() {

            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                Log.d("MainActivity",e.toString());
                Toast.makeText(MainActivity.this,"onError", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNext(MemberBean memberBean) {
                Toast.makeText(MainActivity.this,memberBean.getCode()+"", Toast.LENGTH_SHORT).show();
            }
        };
        HttpUtils.getInstance().getMemberInfo(subscriber,code);
    }


    private void getConfigParams() {
        subscriber=new Subscriber<ConfigBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.d("MainActivity",e.toString());
                Toast.makeText(MainActivity.this,"onError", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNext(ConfigBean configBean) {
                Toast.makeText(MainActivity.this,configBean.getCode()+"", Toast.LENGTH_SHORT).show();
            }
        };
        HttpUtils.getInstance().getConfig(subscriber);
    }


    private void getAllPackages(){
        subscriber= new Subscriber<PackageBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.d("MainActivity",e.toString());
                Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNext(PackageBean packageBean) {
                Toast.makeText(MainActivity.this, "onNext", Toast.LENGTH_SHORT).show();
            }
        };
        HttpUtils.getInstance().getAllPackages(subscriber);
    }
    private void getAllCar() {
        subscriber=new Subscriber<CarListBean>() {
            @Override
            public void onCompleted() {
                Toast.makeText(MainActivity.this, "onCompleted", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(Throwable e) {
                Log.i("MainActivity",e.toString());
                Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNext(CarListBean carListBean) {

            }

        };
        HttpUtils.getInstance().getAllCar(subscriber);
    }


}
